<?php

namespace Home\Controller;

use Think\Controller;

/**
 * 渠道调查
 */
class ChanelController extends CommnController
{
    public function __construct()
    {
        parent::__construct();
    }

    public function user_mark()
    {
        $link_type = I('link_type');
        $vid = I('vid');
        $data = M('chanel_survey_mark', '', 'KEFU')->where(['vid' => $vid, 'type' => $link_type])->field('admin_name,ctime,content')->order('ctime asc')->select();
        foreach ($data as $k => $v) {
            $data[$k]['ctime'] = date('Y-m-d H:i', $v['ctime']);
        }
        $this->assign(array(
            'data' => $data,
            'vid' => $vid,
            'type'=>$link_type,
        ));
        $this->display();
    }
    public function Remarks()
    {
        $link_type = I('link_type');
        $vid = I('vid');
        $this->assign(array(
            'link_type' => $link_type,
            'vid' => $vid,
        ));
        $this->display();

    }
    public function mark()
    {
        $type = I('type');
        $vid = I('vid');
        $content = I('content');
        $arr = array('admin_name' => $_SESSION['name'], 'content' => $content, 'ctime' => time(), 'vid' => $vid, 'type' => $type);
        $add = M('chanel_survey_mark', '', 'KEFU')->add($arr);
        if ($add) {
            add_log('对用户' . $vid . '调查备注ID' . $add);
            $this->ajax('1001', '备注成功');
            die;
        }
        $this->ajax('1002', '备注失败');
        die;
    }


    /**
     *渠道调查
     */

    public function no_cert_list()
    {
        $key=I('user');
        $where=[];
        $where['cert_status']=array('eq',1);
        $where['channel']=array('eq','ch_94474999');
        if(!empty($key)){
            $where['mobile|truename']=array('like','%'.$key.'%');
        }

        $tol=M('user','','USER')->where($where)->count();
        $row = '10';
        $page = new PageController($tol, $row);
        $fpage = $page->fpage();
        $data=M('user','','USER')->where($where)->field('ctime,vid,mobile,sex,truename')->order('ctime desc')->limit($page->listfirst, $page->listRows)->select();
        foreach ($data as $k => $v) {
            //最后沟通记录
            $data[$k]['is_call'] = M('chanel_survey_mark', '', 'KEFU')->where(['vid' => $v['vid'], 'type' => 3])->limit(1)->order('ctime desc')->getField('content');
            $data[$k]['ctime'] = date('Y-m-d H:i:s', $v['ctime']);
            if ($v['sex'] == 1) {
                $data[$k]['sex'] = '男';
            } else if ($v['sex'] == 2) {
                $data[$k]['sex'] = '女';
            } else if ($v['sex'] == 0) {
                $data[$k]['sex'] = '未知';
            }
        }

        $this->assign(array(
            'data' => $data,
            'fpage' => $fpage,
            'page_first' => $page->listfirst,
            'tol' => $tol
        ));

        $this->display();
    }


}